﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Threading;

using Apprender.Web;
using Apprender.Web.Caching;
using Apprender.Compression;

namespace Apprender.Web.Samples.DataServices
{

    public class UserService:AsyncDataService
    {

        public UserService() { }
            

        [DataServiceMethod(ResponseContentType = HttpResponseContentType.Json,
            CacheMode=CacheMode.Disk | CacheMode.Memory,
            CacheDuration = 3600            
            )]
        public User GetUser(uint Id)
        {            
            return new User() { Id = Id, Name = "Shengmin Zhang", Job = "student", School = "Harry Ainlay High School" };
        }

        [DataServiceMethod(ResponseContentType=HttpResponseContentType.Text,
            CacheDuration=3600,
            CacheMode=CacheMode.Disk            
        )]
        public string SayHi(string Name)
        {
            return "Hi " + Name +"! Thanks for using Apprender.NET";
        }
        
        

        public void RemoveCache()
        {
            Dictionary<string, string> values = new Dictionary<string, string>()
            {
                {"Id","1"}
            };

            var cacheKey = CacheProvider.GetCacheKey(values, FullTypeName, "GetUser", this.CompressionEncoding, null);

            CacheProvider.RemoveCache(cacheKey, Context, CacheProvider.DefaultCacheDirectory);
        }
    }

    public class User
    {
        public User() { }

        public uint Id { get; set; }
        public string Name { get; set; }
        public string Job { get; set; }
        public string School { get; set; }
    }

}
